﻿Public Class frmConceptosDeGastos

    Dim pID As Integer 'parametro ID
    Dim res As DialogResult
    Private Sub frmConceptosDeGastos_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Try
            datosCBGrupoGastos() ' carga datos en el combobox CBGrupoGastos
            listaConceptoGastos() ' carga datos en el dataGridView DGV_ConceptoGastos
        Catch ex As Exception
            mensajeError(ex)
        End Try

    End Sub

    Private Sub btnIngresar_Click(sender As Object, e As EventArgs) Handles btnIngresar.Click
        Try


            If txtNombre.Text = "" Or txtValor.Text = "" Or cbGrupoGastos.SelectedIndex = -1 Then
                MessageBox.Show(msjCampoBlanco, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtNombre.Focus()
            Else
                res = MessageBox.Show(msjIngreso, msjTituloModal, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

                If res = Windows.Forms.DialogResult.Yes Then

                    ingresoConceptoGastos(txtNombre.Text, txtAlias.Text, txtValor.Text, cbGrupoGastos.SelectedValue)

                    txtNombre.Clear()
                    txtValor.Clear()
                    txtAlias.Clear()
                    cbGrupoGastos.SelectedIndex = -1
                    txtNombre.Focus()


                Else
                    txtNombre.Focus()

                End If
            End If

        Catch ex As Exception
            mensajeError(ex)
        End Try
    End Sub


    Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles btnEliminar.Click
        res = MessageBox.Show(msjEliminar, msjTituloModal, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        Try
            With DGV_ConceptoGastos

                If .CurrentRow Is Nothing And res = Windows.Forms.DialogResult.Yes Then

                    MessageBox.Show(msjDatoAEliminar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Information)

                ElseIf .CurrentRow IsNot Nothing And res = Windows.Forms.DialogResult.Yes Then

                    pID = .Item(0, .CurrentRow.Index).Value
                    eliminaConceptoGastos(pID)

                End If

            End With


        Catch ex As Exception
            mensajeError(ex)
        End Try

    End Sub


    Private Sub btnEditar_Click(sender As Object, e As EventArgs) Handles btnEditar.Click


        Dim pID As Integer
        Dim pNom As String = ""
        Dim pAlias As String = ""
        Dim pValor As Integer


        Try

            With DGV_ConceptoGastos

                res = MessageBox.Show(msjActualizar, msjTituloModal, MessageBoxButtons.YesNo, MessageBoxIcon.Question)


                If .CurrentRow Is Nothing And res = Windows.Forms.DialogResult.Yes Then

                    MessageBox.Show(msjDatoAActualizar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Information)

                ElseIf res = DialogResult.Yes Then

                    pID = .Item(0, .CurrentCell.RowIndex).Value
                    pNom = .Item(1, .CurrentCell.RowIndex).Value
                    pAlias = .Item(2, .CurrentCell.RowIndex).Value
                    pValor = .Item(3, .CurrentCell.RowIndex).Value



                    actualizaConceptoGastos(pID, pNom, pAlias, pValor)
                End If

            End With



        Catch ex As Exception
            mensajeError(ex)

        End Try
    End Sub


End Class